<template>
  <div>
    <page-main>
      <div ref="lastThirtyDays" style="width: 100%; height: 450px;"></div>
      <div ref="lastTwelveMonth" style="width: 100%; height: 450px;"></div>
    </page-main>
  </div>
</template>

<script>
import Echarts from '@/util/echarts'
import { markRaw } from 'vue'
export default {
  data() {
    return {
      lastThirtyDays: "",
      lastTwelveMonth: "",
    };
  },
  mounted() {
    this.initLastThirtyDaysChart();
    this.initLastTwelveMonth();
  },
  methods: {
    initLastThirtyDaysChart() {
      this.lastThirtyDays = markRaw(Echarts.init(this.$refs.lastThirtyDays));
      let option = {
        title: {
          text: "最近30天",
        },
        tooltip: {
          trigger: "axis",
        },
        legend: {
          data: ["安全指数", "优", "一般"],
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: {
          type: "category",
          boundaryGap: false,
          data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
        },
        yAxis: {
          type: "value",
          axisLabel: {
            formatter: "{value} %",
          },
        },
        series: [
          {
            name: "安全指数",
            type: "line",
            stack: "Total",
            data: [120, 132, 101, 134, 90, 230, 210],
            smooth: true,
          },
          {
            name: "优",
            type: "line",
            stack: "Total",
            data: [220, 182, 191, 234, 290, 330, 310],
            smooth: true,
          },
          {
            name: "一般",
            type: "line",
            stack: "Total",
            data: [150, 232, 201, 154, 190, 330, 410],
            smooth: true,
          },
        ],
      };
      this.lastThirtyDays.setOption(option);
    },
    initLastTwelveMonth() {
      this.lastTwelveMonth = markRaw(Echarts.init(this.$refs.lastTwelveMonth));
      let option = {
        title: {
          text: "最近一年",
        },
        tooltip: {
          trigger: "axis",
        },
        legend: {
          data: ["安全指数", "优", "一般"],
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: {
          type: "category",
          boundaryGap: false,
          data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
        },
        yAxis: {
          type: "value",
          axisLabel: {
            formatter: "{value} %",
          },
        },
        series: [
          {
            name: "安全指数",
            type: "bar",
            stack: "Total",
            data: [120, 132, 101, 134, 90, 230, 210],
            smooth: true,
          },
          {
            name: "优",
            type: "line",
            stack: "Total",
            data: [220, 182, 191, 234, 290, 330, 310],
            smooth: true,
          },
          {
            name: "一般",
            type: "line",
            stack: "Total",
            data: [150, 232, 201, 154, 190, 330, 410],
            smooth: true,
          },
        ],
      };
      this.lastTwelveMonth.setOption(option);
    },
  },
};
</script>

<style>
</style>
